<?php

namespace Frontend\Controllers;

use DuAdmin\Core\BaseController;
use DuAdmin\Helpers\AppHelper;
use Frontend\Forms\ContactForm;
use Yii;

class ContactFormController extends BaseController
{
    public function actionIndex()
    {
        $model = new ContactForm();
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($model->sendEmail(AppHelper::getSetting('site.email'))) {
                Yii::$app->session->setFlash('success', Yii::t('theme', 'Thank you for contacting us. We will respond to you as soon as possible.'));
            } else {
                Yii::$app->session->setFlash('error', Yii::t('theme', 'There was an error sending your message.'));
            }
            return $this->refresh();
        } else {
            return $this->render('index', [
                'model' => $model
            ]);
        }
    }
}
